#!/usr/bin/env python

# Created on 4.7.08 by Tizian Schmidlin
# Utils for the parser

from datetime import date
import time
class ParseUtils:
  def __init__(self):
    self.Months = {'Jan':1,
                   'Feb':2,
                   'Mar':3,
                   'Apr':4,
                   'May':5,
                   'Jun':6,
                   'Jul':7,
                   'Aug':8,
                   'Sep':9,
                   'Oct':10,
                   'Nov':11,
                   'Dec':12}
  # split the date so that it can be solved
  def splitdate(self, c):
    da = date(int(c[5:9]),
              self.Months[c[2:5]],
              int(c[0:2]))
    return date
  
  # split the time so that it can be solved
  def splittime(self,t):
    return t[0:2]*3600 + t[3:5] * 60 + t[6:8]
  
  def mergedict(self, dict1, dict2):
    for dic, c in dict2.items():
      dict1.setdefault(dic, 0)
      dict1[dic] += c
  
  # Sort function
  def sortfunc(self,x,y):
    return cmp(y[1],x[1])